<?php namespace Summer\Shop\Models;

use Model;
use Winter\Storm\Database\Traits\SoftDelete;

/**
 * Model
 */
class ProductModel extends Model
{
    use \Winter\Storm\Database\Traits\Validation;
    use SoftDelete;
    protected $dates = ['deleted_at'];

    protected $appends = ['image'];

    /**
     * @var string The database table used by the model.
     */
    public $table = 'summer_shop_products';
    protected $jsonable = ['variants','service_ids','params'];
    /**
     * @var array Validation rules
     */
    public $rules = [
        'name'                         => 'required',
        'slug'                         => ['regex:/^[a-z0-9\/\:_\-\*\[\]\+\?\|]*$/i'],
        'price' => 'required',
        'weight'                       => 'nullable|integer',
        'height'                       => 'nullable|integer',
        'length'                       => 'nullable|integer',
        'width'                        => 'nullable|integer',
    ];
    public $belongsTo = [
        'category' => [CategoryModel::class],
        'brand'    => [BrandModel::class],
    ];
    public $attachOne = [
        'image_preview' => 'System\Models\File',
    ];
    public $attachMany = ['images' => 'System\Models\File'];

    public function getServiceIdsOptions(){
        return ServiceModel::pluck('name','id');
    }

    public function getImageAttribute()
    {
        return $this->image_preview->path;
    }


}
